struct _TransferData
{
StClipboard *clipboard;
- StClipboardCallbackFunc callback;
+ GCallback callback;
gpointer user_data;
GOutputStream *stream;
};
memcpy (text, g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->stream)), data_size);
}
- data->callback (data->clipboard, text, data->user_data);
+ ((StClipboardCallbackFunc) data->callback) (data->clipboard, text,
+ data->user_data);
g_object_unref (data->stream);
g_free (data);
g_free (text);
}
+static void
+transfer_bytes_cb (MetaSelection *selection,
+ GAsyncResult *res,
+ TransferData *data)
+{
+ GBytes *bytes = NULL;
+
+ if (meta_selection_transfer_finish (selection, res, NULL))
+ bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (data->stream));
+
+ ((StClipboardContentCallbackFunc) data->callback) (data->clipboard, bytes,
+ data->user_data);
+ g_object_unref (data->stream);
+ g_clear_pointer (&bytes, g_bytes_unref);
+}
+
/**
* st_clipboard_get_mimetypes:
* @clipboard: a #StClipboard
data = g_new0 (TransferData, 1);
data->clipboard = clipboard;
- data->callback = callback;
+ data->callback = G_CALLBACK (callback);
data->user_data = user_data;
data->stream = g_memory_output_stream_new_resizable ();
data);
}
+/**
+ * st_clipboard_get_content:
+ * @clipboard: A #StCliboard
+ * @type: The type of clipboard data you want
+ * @mimetype: The mimetype to get content for
+ * @callback: (scope async): function to be called when the type is retrieved
+ * @user_data: data to be passed to the callback
+ *
+ * Request the data from the clipboard in #GBytes form. @callback is executed
+ * when the data is retrieved.
+ *
+ */
+void
+st_clipboard_get_content (StClipboard *clipboard,
+ StClipboardType type,
+ const gchar *mimetype,
+ StClipboardContentCallbackFunc callback,
+ gpointer user_data)
+{
+ MetaSelectionType selection_type;
+ TransferData *data;
+
+ g_return_if_fail (ST_IS_CLIPBOARD (clipboard));
+ g_return_if_fail (meta_selection != NULL);
+ g_return_if_fail (callback != NULL);
+
+ if (!mimetype || !convert_type (type, &selection_type))
+ {
+ callback (clipboard, NULL, user_data);
+ return;
+ }
+
+ data = g_new0 (TransferData, 1);
+ data->clipboard = clipboard;
+ data->callback = G_CALLBACK (callback);
+ data->user_data = user_data;
+ data->stream = g_memory_output_stream_new_resizable ();
+
+ meta_selection_transfer_async (meta_selection,
+ selection_type,
+ mimetype, -1,
+ data->stream, NULL,
+ (GAsyncReadyCallback) transfer_bytes_cb,
+ data);
+}
+
/**
* st_clipboard_set_content:
* @clipboard: A #StClipboard
const gchar *text,
gpointer user_data);
+/**
+ * StClipboardContentCallbackFunc:
+ * @clipboard: A #StClipboard
+ * @bytes: content from the clipboard
+ * @user_data: user data
+ *
+ * Callback function called when content is retrieved from the clipboard.
+ */
+typedef void (*StClipboardContentCallbackFunc) (StClipboard *clipboard,
+ GBytes *bytes,
+ gpointer user_data);
+
StClipboard* st_clipboard_get_default (void);
GList * st_clipboard_get_mimetypes (StClipboard *clipboard,
StClipboardType type,
const gchar *mimetype,
GBytes *bytes);
+void st_clipboard_get_content (StClipboard *clipboard,
+ StClipboardType type,
+ const gchar *mimetype,
+ StClipboardContentCallbackFunc callback,
+ gpointer user_data);
void st_clipboard_set_selection (MetaSelection *selection);